<!--
* 主机界面
*
* @author lock
* @since 2022-06-16 18:45:26
* @version 1.0
-->

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>主机管理</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">主机ID</label>
                    <div class="layui-input-inline">
                        <input type="text" id="hostid" name="hostid" required=false placeholder="请输入主机id" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <a id="searchID" class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </a>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">主机名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="hostname" name="hostname" required=false placeholder="请输入主机名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <a id="searchname" class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </a>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i id="iReset" class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="host-table" lay-filter="host-table"></table>
    </div>
</div>

<script type="text/html" id="host-toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm" lay-event="insertHost">新增主机</button>
    </div>
</script>

<script type="text/html" id="host-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>

<script type="text/html" id="insert_form">
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_id" name="insert_id" lay-verify="title"
                               autocomplete="off" placeholder="请输入ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主机名</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_name" name="insert_name" lay-verify="title"
                               autocomplete="off" placeholder="请输入主机名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">IP</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_ip" name="insert_ip" lay-verify="title"
                               autocomplete="off" placeholder="请输入ip" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">操作版本</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_os" name="insert_os" lay-verify="title"
                               autocomplete="off" placeholder="请输入操作版本" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">MAC</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_mac" name="insert_mac" lay-verify="title"
                               autocomplete="off" placeholder="请输入MAC" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备操作系统位</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_OsBit" name="insert_OsBit" lay-verify="title"
                               autocomplete="off" placeholder="请输入操作系统位" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">系统语言</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_OsLanguage" name="insert_OsLanguage" lay-verify="title"
                               autocomplete="off" placeholder="请输入系统语言" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">系统序列号</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_OsCode" name="insert_OsCode" lay-verify="title"
                               autocomplete="off" placeholder="请输入系统序列号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_cpunum" name="insert_cpunum" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU类型</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_cputype" name="insert_cputype" lay-verify="title"
                               autocomplete="off" placeholder="请输入PU类型" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板厂商</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_mainboardinc" name="insert_mainboardinc" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板厂商" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_mainboardid" name="insert_mainboardid" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板型号</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_mainboardtype" name="insert_mainboardtype" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板型号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板架构</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_mainboard_srtucture" name="insert_mainboard_srtucture" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板架构" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU容量</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_memory_size" name="insert_memory_size" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU容量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU频率</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_cpu_frequency" name="insert_cpu_frequency" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU频率" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU缓存</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_cpu_cache" name="insert_cpu_cache" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU缓存" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU核数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_cpu_core" name="insert_cpu_core" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU核数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU宽度</label>
                    <div class="layui-input-block">
                        <input type="text" id="insert_cpu_width" name="insert_cpu_width" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU宽度" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
    </form>
</script>

<script type="text/html" id="update_form">
    <form class="layui-form" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_id" name="update_id" lay-verify="title"
                               autocomplete="off" placeholder="请输入ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主机名</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_name" name="update_name" lay-verify="title"
                               autocomplete="off" placeholder="请输入主机名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">IP</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_ip" name="update_ip" lay-verify="title"
                               autocomplete="off" placeholder="请输入ip" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">操作版本</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_os" name="update_os" lay-verify="title"
                               autocomplete="off" placeholder="请输入操作版本" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">MAC</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_mac" name="update_mac" lay-verify="title"
                               autocomplete="off" placeholder="请输入MAC" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备操作系统位</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_OsBit" name="update_OsBit" lay-verify="title"
                               autocomplete="off" placeholder="请输入操作系统位" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">系统语言</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_OsLanguage" name="update_OsLanguage" lay-verify="title"
                               autocomplete="off" placeholder="请输入系统语言" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">系统序列号</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_OsCode" name="update_OsCode" lay-verify="title"
                               autocomplete="off" placeholder="请输入系统序列号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_cpunum" name="update_cpunum" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU类型</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_cputype" name="update_cputype" lay-verify="title"
                               autocomplete="off" placeholder="请输入PU类型" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板厂商</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_mainboardinc" name="update_mainboardinc" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板厂商" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_mainboardid" name="update_mainboardid" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板型号</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_mainboardtype" name="update_mainboardtype" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板型号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">主板架构</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_mainboard_srtucture" name="update_mainboard_srtucture" lay-verify="title"
                               autocomplete="off" placeholder="请输入主板架构" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU容量</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_memory_size" name="update_memory_size" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU容量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU频率</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_cpu_frequency" name="update_cpu_frequency" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU频率" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU缓存</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_cpu_cache" name="update_cpu_cache" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU缓存" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU核数量</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_cpu_core" name="update_cpu_core" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU核数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">CPU宽度</label>
                    <div class="layui-input-block">
                        <input type="text" id="update_cpu_width" name="update_cpu_width" lay-verify="title"
                               autocomplete="off" placeholder="请输入CPU宽度" class="layui-input">
                    </div>
                </div>
            </div>
        </div>

    </form>
</script>



<script type="text/html" id="host-enable">
    <input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="host-enable"
           checked="{{ d.enable == 0 ? 'true' : 'false' }}">
</script>

<script src="../component/layui/layui.js"></script>
<script src="../component/pear/pear.js"></script>
<script src="../component/jquery/jquery-3.6.0.js" charset="utf-8"></script>

<script>
    layui.config({
        version: '1554901098009' //为了更新 js 缓存，可忽略
    });

    $("#iReset").click(function () {
        $("#hostid").val("");
        $("#hostname").val("")
        let hostid = $("#hostid").val();
        let hostname = null;
        tableFlush(hostname,hostid);
    });

    $("#searchID").click(function () {
        let hostid = $("#hostid").val();
        let hostname = null;
        tableFlush(hostname,hostid);
    });

    $("#searchname").click(function () {
        let hostname = $("#hostname").val();
        let hostid = null;
        tableFlush(hostname,hostid);
    });

    function tableFlush(hostname,hostid) {
        layui.use(['table', 'form',  'common','util'], function () {
            let table = layui.table;
            let layer = layui.layer ;//弹层
            let util = layui.util;
            let common = layui.common;
            console.log(hostid);
            if (hostid != null && hostid != '') {
                    table.render({
                        elem: '#host-table',
                        url: '/host/selectsimplebyid?id='+hostid,
                        page: true,
                        parseData:function(res){
                            console.log(res);
                            return{
                                "code":0,
                                "msg":"",
                                "data":res.res,
                            }
                        },
                        title: '主机表',
                        cols: [[
                            {type: 'checkbox', fixed: 'left'}
                            , {
                                field: 'hostId', title: '主机ID', unresize: true,templet: function (res) {
                                    return '<em>' + res.hostId + '</em>'
                                }
                            }
                            , {
                                field: 'hostName', title: '主机名', templet: function (res) {
                                    return '<em>' + res.hostName + '</em>'
                                }
                            }
                            , {
                                field: 'hostIpv4', title: '主机ip',  templet:  function (res) {
                                    return  '<em>' +  res.hostIpv4 + '</em>'
                                }
                            }
                            , {
                                field: 'hostOs', title: '用户OS',   templet: function (res) {
                                    return  '<em>' +  res.hostOs + '</em>'
                                }
                            }
                            , {fixed: 'right', title: '操作', toolbar: '#host-bar', width: 150}
                        ]],
                        skin: 'line',
                        toolbar: '#host-toolbar',
                        defaultToolbar: [{
                            title: '刷新',
                            layEvent: 'refresh',
                            icon: 'layui-icon-refresh',
                        }, 'filter', 'print', 'exports']
                    });
            }
            else if (hostname != null && hostname != '') {
                    let search_json ={};
                    search_json.hostName = hostname;
                    search_json.page=1;
                    table.render({
                        elem: '#host-table',
                        url: '/host/selectbyhostname',
                        where:search_json,
                        parseData:function(res){
                            //console.log(res);
                            return{
                                "code":0,
                                "msg": "",
                                "data":res.res,
                            };
                        },
                        page: true,
                        title: '主机表',
                        cols: [[
                            {type: 'checkbox', fixed: 'left'}
                            , {
                                field: 'hostId', title: '主机ID', unresize: true,templet: function (res) {
                                    console.log(res);
                                    return '<em>' + res.hostId+ '</em>';

                                }
                            }
                            , {
                                field: 'hostName', title: '主机名', templet: function (res) {
                                    return '<em>' + res.hostName + '</em>'
                                }
                            }
                            , {
                                field: 'hostIpv4', title: '主机ip',  templet:  function (res) {
                                    return  '<em>' +  res.hostIpv4 + '</em>'
                                }
                            }
                            , {
                                field: 'hostOs', title: '用户OS',   templet: function (res) {
                                    return  '<em>' +  res.hostOs + '</em>'
                                }
                            }

                            , {fixed: 'right', title: '操作', toolbar: '#host-bar', width: 150}
                        ]],
                        skin: 'line',
                        toolbar: '#host-toolbar',
                        defaultToolbar: [{
                            title: '刷新',
                            layEvent: 'refresh',
                            icon: 'layui-icon-refresh',
                        }, 'filter', 'print', 'exports']
                    });
            }
            else {
                table.render({
                        elem: '#host-table',
                        url: '/host/findhostlist',
                        page: true,
                        title: '主机表',
                    parseData:function(res){
                        //console.log(res);
                        return{
                            "code":0,
                            "msg": "",
                            "data":res,
                        };
                    },
                        cols: [[
                            {type: 'checkbox', fixed: 'left'}
                            , {
                                field: 'hostid', title: '主机ID', unresize: true, templet: function (res) {
                                    return '<em>' + res.hostId + '</em>'
                                }
                            }
                            , {
                                field: 'hostName', title: '主机名', templet: function (res) {
                                    return '<em>' + res.hostName + '</em>'
                                }
                            }
                            , {
                                field: 'hostipv4', title: '主机ip',  templet: function (res) {
                                    return '<em>' + res.hostIpv4 + '</em>'
                                }
                            }
                            , {
                                field: 'hostOs', title: '用户OS',  templet: function (res) {
                                    return '<em>' + res.hostOs + '</em>'
                                }
                            }

                            , {fixed: 'right', title: '操作', toolbar: '#host-bar', width: 150}
                        ]],
                        skin: 'line',
                        toolbar: '#host-toolbar',
                        defaultToolbar: [{
                            title: '刷新',
                            layEvent: 'refresh',
                            icon: 'layui-icon-refresh',
                        }, 'filter', 'print', 'exports']
                    });
            }




            //头工具栏事件
            table.on('toolbar(host-table)', function(obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;             // jsonArray
                        layer.alert(JSON.stringify(data));       // 把一个jsonArray转换为字符串输出
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：'+ data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选': '未全选');
                        break;
                    case 'insertHost':   // 新增用户
                        layer.open({     // 弹出框处理  模态框
                            type: 1               // 模态框
                            ,title: '新增主机' //不显示标题栏
                            ,closeBtn: false
                            ,area: ['500px','500px']  // 宽和高
                            ,shade: 0.5
                            ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                            ,btn: ['新增', '取消']
                            ,btnAlign: 'c'
                            ,moveType: 1 //拖拽模式，0或者1
                            ,content: $('#insert_form').html()         // 引入自定义表单
                            ,btn1: function(index, layero){            // 这个是新增按钮点击事件
                                // layer.msg("新增按钮执行");
                                let hostId = $("#insert_id").val();
                                let hostName = $("#insert_name").val();
                                let hostIpv4 = $("#insert_ip").val();
                                let hostOs = $("#insert_os").val();
                                let hostMac = $("#insert_mac").val();
                                let hostOsBit = $("#insert_OsBit").val();
                                let hostOsLanguage= $("#insert_OsLanguage").val();
                                let hostOsCode = $("#insert_OsCode").val();
                                let hostCpuNum= $("#insert_cpunum").val();
                                let hostCpuType = $("#insert_cputype").val();
                                let hostMainboardInc = $("#insert_mainboardinc").val();
                                let hostMainboardId = $("#insert_mainboardid").val();
                                let hostMainboardType = $("#insert_mainboardtype").val();
                                let hostMainboardStructure = $("#insert_mainboard_srtucture").val();
                                let hostMemorySize = $("#insert_memory_size").val();
                                let hostCpuFrequency = $("#insert_cpu_frequency").val();
                                let hostCpuCache = $("#insert_cpu_cache").val();
                                let hostCpuCore = $("#insert_cpu_core").val();
                                let hostCpuWidth = $("#insert_cpu_width").val();
                                $.ajax({
                                    url:"/host/insert",           // 请求路径
                                    type:"post",                  // 请求的方式，不区分大小写
                                    cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                    contentType:"application/json;charset=utf-8",
                                    data: JSON.stringify({
                                        hostId:hostId,
                                        hostName:hostName,
                                        hostIpv4:hostIpv4,
                                        hostOs:hostOs,
                                        hostMac:hostMac,
                                        hostOsBit:hostOsBit,
                                        hostOsLanguage:hostOsLanguage,
                                        hostOsCode: hostOsCode,
                                        hostCpuNum: hostCpuNum,
                                        hostCpuType :hostCpuType,
                                        hostMainboardInc :hostMainboardInc,
                                        hostMainboardId : hostMainboardId,
                                        hostMainboardType : hostMainboardType,
                                        hostMainboardStructure :hostMainboardStructure,
                                        hostMemorySize :hostMemorySize,
                                        hostCpuFrequency :hostCpuFrequency,
                                        hostCpuCache : hostCpuCache,
                                        hostCpuCore :hostCpuCore,
                                        hostCpuWidth :hostCpuWidth
                                    }),
                                    datatype:"json",        // 返回类型，text文本、html页面、json数据
                                    success:function(response){
                                        console.log("返回: " + response);
                                        if(response.code === 200) {
                                            layer.msg("新增用户成功!");
                                            layer.close(index);                         // 关闭当前窗口
                                            tableFlush();
                                        }
                                    },
                                    error:function(response){
                                        console.log("出错返回: " + response);
                                    }
                                });
                            }
                            ,success: function(layero){

                            }
                        });
                        break;
                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });



            table.on('tool(host-table)', function (obj) {
                let data = obj.data;
                console.log(JSON.stringify(data));

                if (obj.event === 'remove') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: "/host/deletebyid?id="+ data.hostId,       // 请求路径
                            type:"GET",
                            contentType:"application/json",//设置请求参数类型为json字符串
                            cache: false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                            datatype: "json",             // 返回类型，text文本、html页面、json数据
                            success: function (response) {
                                console.log("返回: " + response);
                                if (response.code === 200) {
                                    layer.msg("删除用户成功!");
                                    layer.close(index);                         // 关闭当前窗口
                                    tableFlush();
                                }
                            },
                            error: function (response) {
                                console.log("出错返回: " + response);
                            }
                        });
                    });
                } else if (obj.event === 'edit') {
                    layer.open({     // 弹出框处理  模态框
                        type: 1               // 模态框
                        ,title: '更新主机' //不显示标题栏
                        ,closeBtn: false
                        ,area: ['500px','500px']  // 宽和高
                        ,shade: 0.5
                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                        ,btn: ['更新', '取消']
                        ,btnAlign: 'c'
                        ,moveType: 1 //拖拽模式，0或者1
                        ,content: $('#update_form').html()
                        ,btn1: function(index, layero){            // 这个是新增按钮点击事件

                            let hostId = $("#update_id").val();
                            let hostName = $("#update_name").val();
                            let hostIpv4 = $("#update_ip").val();
                            let hostOs = $("#update_os").val();
                            let hostMac = $("#update_mac").val();
                            let hostOsBit = $("#update_OsBit").val();
                            let hostOsLanguage=  $("#update_OsLanguage").val();
                            let hostOsCode = $("#update_OsCode").val();
                            let hostCpuNum= $("#update_cpunum").val();
                            let hostCpuType = $("#update_cputype").val();
                            let hostMainboardInc = $("#update_mainboardinc").val();
                            let hostMainboardId = $("#update_mainboardid").val();
                            let hostMainboardType = $("#update_mainboardtype").val();
                            let hostMainboardStructure = $("#update_mainboard_srtucture").val();
                            let hostMemorySize = $("#update_memory_size").val();
                            let hostCpuFrequency = $("#update_cpu_frequency").val();
                            let hostCpuCache =  $("#update_cpu_cache").val();
                            let hostCpuCore = $("#update_cpu_core").val();
                            let hostCpuWidth = $("#update_cpu_width").val();

                            $.ajax({
                                url:"/host/editbymap",           // 请求路径
                                type:"post",                  // 请求的方式，不区分大小写
                                cache:false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                contentType:"application/json;charset=utf-8",
                                data: JSON.stringify({
                                    hostId:hostId,
                                    hostName:hostName,
                                    hostIpv4:hostIpv4,
                                    hostOs:hostOs,
                                    hostMac:hostMac,
                                    hostOsBit:hostOsBit,
                                    hostOsLanguage:hostOsLanguage,
                                    hostOsCode: hostOsCode,
                                    hostCpuNum: hostCpuNum,
                                    hostCpuType :hostCpuType,
                                    hostMainboardInc :hostMainboardInc,
                                    hostMainboardId : hostMainboardId,
                                    hostMainboardType : hostMainboardType,
                                    hostMainboardStructure :hostMainboardStructure,
                                    hostMemorySize :hostMemorySize,
                                    hostCpuFrequency :hostCpuFrequency,
                                    hostCpuCache : hostCpuCache,
                                    hostCpuCore :hostCpuCore,
                                    hostCpuWidth :hostCpuWidth
                                }),
                                datatype:"json",        // 返回类型，text文本、html页面、json数据
                                success:function(response){
                                    console.log("返回: " + response);
                                    if(response.code === 200) {
                                        layer.msg("更新主机成功!");
                                        layer.close(index);                         // 关闭当前窗口
                                        tableFlush();
                                    }
                                },
                                error:function(response){
                                    console.log("出错返回: " + response);
                                }
                            });
                        }
                        ,success: function(layero){
                            var json = {};
                            $.ajax({
                                url:"/host/findhostbyid?id="+data.hostId,           // 请求路径
                                type:"get",                  // 请求的方式，不区分大小写
                                cache:false,
                                datatype:"json",        // 返回类型，text文本、html页面、json数据
                                success:function(data){
                                    if(data.code===200) {
                                        json = data.res[0];
                                        console.log(data.res[0]);
                                        $("#update_id").val(json.hostId);
                                        $("#update_name").val(json.hostName);
                                        $("#update_ip").val(json.hostIpv4);
                                        $("#update_os").val(json.hostOs);
                                        $("#update_mac").val(json.hostMac);
                                        $("#update_OsBit").val(json.hostOsBit);
                                        $("#update_OsLanguage").val(json.hostOsLanguage);
                                        $("#update_OsCode").val(json.hostOsCode);
                                        $("#update_cpunum").val(json.hostCpuNum);
                                        $("#update_cputype").val(json.hostCpuType);
                                        $("#update_mainboardinc").val(json.hostMainboardInc);
                                        $("#update_mainboardid").val(json.hostMainboardId);
                                        $("#update_mainboardtype").val(json.hostMainboardType);
                                        $("#update_mainboard_srtucture").val(json.hostMainboardStructure);
                                        $("#update_memory_size").val(json.hostMemorySize);
                                        $("#update_cpu_frequency").val(json.hostCpuFrequency);
                                        $("#update_cpu_cache").val(json.hostCpuCache);
                                        $("#update_cpu_core").val(json.hostCpuCore);
                                        $("#update_cpu_width").val(json.hostCpuWidth);
                                    }
                                },
                                error:function(response){
                                    console.log("出错返回: " + response);
                                }
                            });


                        }
                    });
                }
            });
        })
    }
    tableFlush();
</script>
</body>
</html>
